package com.ytjj.qmyx.admin.service.impl;

import com.ytjj.qmyx.admin.dao.DynamicAndTopicDao;
import com.ytjj.qmyx.admin.model.response.DynamicAndTopicResponse;
import com.ytjj.qmyx.admin.service.DynamicAndTopicService;
import com.ytjj.qmyx.mall.mapper.DynamicAndTopicMapper;
import com.ytjj.qmyx.mall.model.DynamicAndTopic;
import com.ytjj.qmyx.mall.model.DynamicAndTopicExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 *
 * 
 * @description:
 */
@Service
public class DynamicAndTopicServiceImpl implements DynamicAndTopicService {

    @Autowired
    private DynamicAndTopicMapper dynamicAndTopicMapper;

    @Autowired
    private DynamicAndTopicDao dynamicAndTopicDao;

    @Override
    public Integer delByDynamicId(Integer dynamicId)  {
        DynamicAndTopicExample dynamicAndTopicExample = new DynamicAndTopicExample();
        dynamicAndTopicExample.createCriteria().andDynamicIdEqualTo(dynamicId);
        return dynamicAndTopicMapper.deleteByExample(dynamicAndTopicExample);
    }

    @Override
    public boolean createDynamicTopicRelations(Integer dynamicId, List<Integer> topicIds,Integer sort) {
        for (Integer integer : topicIds) {
            DynamicAndTopic dynamicAndTopic = new DynamicAndTopic();
            dynamicAndTopic.setCreateTime(new Date());
            dynamicAndTopic.setDynamicId(dynamicId);
            dynamicAndTopic.setTopicId(integer);
            dynamicAndTopic.setSort(sort);
            dynamicAndTopicMapper.insertSelective(dynamicAndTopic);
        }
        return true;
    }

    @Override
    public DynamicAndTopicResponse getRelationsByDynamicId(Integer dynamicId) {
        return dynamicAndTopicDao.getRelationsByDynamicId(dynamicId);
    }
}
